from selenium import webdriver
from selenium.webdriver.common.by import By

from page_object.common.base_page import Base_Page
class Page_Login(Base_Page): #创建登录页面的类
    def __init__(self,driver):
        # driver=webdriver.Chrome()
        super().__init__(driver)
#元素定位
    #用户名
    user_name = (By.ID,"username")
    #密码
    password = (By.ID,"password")
    #验证码
    code = (By.ID, 'verify_code')
    #登录按钮
    submit = (By.NAME,"sbtbutton")
    #登录错误信息弹窗
    err_msg=(By.CSS_SELECTOR,".layui-layer-content.layui-layer-padding")
#元素操作
    #输入用户名
    def login(self,username,password,code):
        self.ele_input(self.user_name,"登录模块-用户名",username)
        self.ele_input(self.password,"登录模块-密码",password)
        self.ele_input(self.code,"登录模块-验证码",code)
        self.ele_click(self.submit,"登录模块-点击登录")
    #登录失败时获取异常信息
    def get_err_msg_text(self):
        err_result = self.ele_get_text(self.err_msg,"登录模块-登陆失败异常信息")
        return err_result
